package com.zhihui.online.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhihui.online.entity.Teacher;
import com.zhihui.online.exception.MyCustomerException;
import com.zhihui.online.mapper.TeacherMapper;
import com.zhihui.online.service.TeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhihui.online.dto.teacher.TeacherPageDTO;
import com.zhihui.online.utils.ResultCodeEnum;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 教师表 服务实现类
 * </p>
 *
 * @author 程序员阿良,21岁纯情后爸,懒得想名字
 * @since 2024-08-01
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {

    @Override

    public IPage<Teacher> listPagedTeachers(IPage<Teacher> iPage, TeacherPageDTO teacherPageDTO) {
        return this.baseMapper.listPagedTeachers(iPage, teacherPageDTO);

    }


    @Override
    public void updateStatus(Long id, Integer status) {
        //查询数据库，判断使用有数据
        Teacher teacher = this.baseMapper.selectById(id);
        if (teacher == null) {
            throw new MyCustomerException(ResultCodeEnum.ACCOUNT_ERROR);
        }
        //封装存储对象
        Teacher teacher1 = new Teacher();
        teacher1.setStatus(status);
        teacher1.setId(id);
        //更新对象
        this.baseMapper.updateById(teacher1);
    }

}
